package cn.com.gzheroli.rabbitmq.service.consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import cn.com.gzheroli.rabbitmq.listener.TopicQueueListener;
import cn.com.gzheroli.rabbitmq.service.producer.TopicProducerService;

/**
 * Created by lhx on 2016/9/5 17:52
 *
 * @Description
 */
public class TopicConsumer{
	
	private static final Logger logger = LoggerFactory.getLogger(TopicQueueListener.class);
    public static void main(final String... args) throws Exception {
        AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("RabbitMQ.xml");
        TopicProducerService topicProducer = (TopicProducerService) ctx.getBean("topicProducerService");
        //topicProducer.sendMessage("++++++++++++++++++hello,xin3453465465467456456456^^^^^^66666!hello,xin");
       // topicProducer.sendMessage1("weewewewewre");
        /*RabbitTemplate template = (RabbitTemplate) ctx.getBean("topicTemplate");
        template.convertAndSend(template.getExchange(), "ccs.binding.test", "id=111111",new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setHeader("jobName", "jobName");
                return message;
            }
        });*/
        RabbitTemplate topicTemplate = (RabbitTemplate) ctx.getBean("topicTemplate");
        String exchange=topicTemplate.getExchange();
        String routingKey="ccs.binding.test";
        Object object= "i1222d=111111";
        /*topicTemplate.convertAndSend(exchange, routingKey, message,new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setHeader("jobName", "jobName");
                return message;
            }
        });*/
        topicTemplate.convertAndSend(exchange, routingKey, object);
        Thread.sleep(1000);
        ctx.destroy();
    }
}
